<!DOCTYPE html>

<html>

	<head>
		<meta charset="utf-8">
		<title>鹏轩云SAAS服务平台-登录</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../layuiadmin/style/login.css" media="all">
	</head>

	<body>

		<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">

			<div class="layadmin-user-login-main">
				<div class="layadmin-user-login-box layadmin-user-login-header">
					<h2>鹏轩云</h2>
					<p>SAAS服务平台</p>
				</div>
				<!-- 密码登录 -->
				<div class="layadmin-user-login-box layadmin-user-login-body layui-form" id="password">
					<div class="layui-form-item">
						<label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
						<input type="text" name="account" id="LAY-user-login-username" lay-verify="required| " placeholder="用户名" class="layui-input">
					</div>
					<div class="layui-form-item">
						<label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
						<input type="password" name="code" id="LAY-user-login-password" lay-verify="required" placeholder="密码" class="layui-input">
					</div> 
					<div class="layui-form-item" style="margin-bottom: 20px;">
						<input type="checkbox" name="remember" lay-skin="primary" title="记住密码" checked id="remember"> 
						<a href="user_center/forget.html" class="layadmin-user-jump-change layadmin-link" style="margin-top: 7px;">忘记密码？</a>
					</div>
					<div class="layui-form-item">
						<button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-login-submit">登录</button>
					</div> 
					<div class="layui-form-item">
						<button class="layui-btn layui-btn-primary"  style="width: 100%;" onclick="smscode_show()">验证码登录</button>
					</div>
				</div>
				<!-- 验证码登录 -->
				<div class="layadmin-user-login-box layadmin-user-login-body layui-form" id="smscode" style="display: none;">
					<div class="layui-form-item">
						<label class="layadmin-user-login-icon layui-icon layui-icon-cellphone" for="LAY-user-login-cellphone"></label>
						<input type="text" name="mobile" lay-verify="phone" placeholder="请输入注册时的手机号" class="layui-input">
					</div>
					<div class="layui-form-item">
						<div class="layui-row">
							<div class="layui-col-xs7">
								<label class="layadmin-user-login-icon layui-icon layui-icon-vercode"></label>
								<input type="text" name="smscode" lay-verify="required" placeholder="短信验证码" class="layui-input">
							</div>
							<div class="layui-col-xs5">
								<div style="margin-left: 10px;">
									<button type="button" class="layui-btn layui-btn-primary layui-btn-fluid" id="getsmscode">获取验证码</button>
								</div>
							</div>
						</div>
					</div>
					 
					<div class="layui-form-item">
						<button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-login-smscode-submit">登录</button>
					</div>
					<div class="layui-form-item">
						<button class="layui-btn layui-btn-primary"  style="width: 100%;" onclick="password_show()">密码登录</button>
					</div>
				</div>
			</div>

			<!--<div class="layui-trans layadmin-user-login-footer">

				<p>© 2018
					<a href="http://www.layui.com/" target="_blank">layui.com</a>
				</p>
				<p>
					<span><a href="http://www.layui.com/admin/#get" target="_blank">获取授权</a></span>
					<span><a href="http://www.layui.com/admin/pro/" target="_blank">在线演示</a></span>
					<span><a href="http://www.layui.com/admin/" target="_blank">前往官网</a></span>
				</p>
			</div>-->
			
		</div>
		 <script src="../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../layuiadmin/layui/layui.js"></script>
		<script src="../js/common.js"></script>
		<script>
			_data = {
				type:getParam("type")
			}
			localStorage.removeItem('curChooseProjectId')
			localStorage.removeItem('pxy_shopid');
			localStorage.removeItem('pxy_shopname');
			localStorage.removeItem('pxy_shopscene');
			localStorage.removeItem('pxy_parent_shopid');
			localStorage.removeItem('pxy_parent_shopname');
			window.password_show = function password_show(){ 
					document.getElementById("smscode").style.display =  "none"
					document.getElementById("password").style.display = "block"
			}
			window.smscode_show = function smscode_show(){
					document.getElementById("smscode").style.display =  "block"
					document.getElementById("password").style.display = "none"
			} 
			
			layui.config({
				base: '../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'user'], function() {
				var $ = layui.$,
					setter = layui.setter,
					admin = layui.admin,
					form = layui.form,
					router = layui.router(),
					search = router.search;

				form.render(); 
				//提交
				form.on('submit(LAY-user-login-submit)', function(obj) {
					// console.log(obj.field);
					//请求登入接口
					loading();
					submitdata(obj.field);
				});
				function submitdata(_data){
					$.post(server.login,_data,function(res,status){
						if(status == 'success'){
							if(res.code == 0){
								layer.msg('登录成功',{time: 200},function(){
									var checked = $("#remember").prop("checked")
									var role_main_page = res.role.data.main_page || ''
									var role_main_page_vue = res.role.data.vue_page
									if (checked) {
										cookie.SetCookie('role_main_page',role_main_page,365,domain,'/')
										cookie.SetCookie('role_main_page_vue',role_main_page_vue,365,domain,'/')
										cookie.SetCookie('shop_token',res.system_token.data.token,365,domain,'/')
										cookie.SetCookie('shop_uid',res.system_token.data.userid,365,domain,'/')
										cookie.SetCookie('shop_roleid',res.member.data.role_id,365,domain,'/')
									}else{
										cookie.SetCookie('shop_token',res.system_token.data.token,false,domain,'/')
										cookie.SetCookie('shop_uid',res.system_token.data.userid,false,domain,'/')
										cookie.SetCookie('shop_roleid',res.member.data.role_id,false,domain,'/')
										cookie.SetCookie('role_main_page',role_main_page,false,domain,'/')
										cookie.SetCookie('role_main_page_vue',role_main_page_vue,false,domain,'/')
									} 
									//cookie.SetCookie('type',res.member.data.type,365,domain,'/')
									//cookie.SetCookie('memberid',res.system_user_data.data.memberid,365,domain,'/')
									location = '../index.html'
								});
							} else {
								layer.msg(res.msg);
							}
							closeloading();
						} else {
							layer.msg('服务器连接错误');
						}
					})
				}
				
				// 验证码操作
				var countdown =''
				var  _generate_code = $("#getsmscode")
				function settime() {
					if (countdown == 0) {
						_generate_code.attr("disabled", false);
						_generate_code.removeClass("layui-btn-disabled");
						_generate_code.html("获取验证码");
						countdown = 60;
						return false;
					} else {
						_generate_code.attr("disabled", true);
						_generate_code.addClass("layui-btn-disabled");
						_generate_code.html("重新发送(" + countdown + ")");
						countdown--;
					}
					setTimeout(function() {
						settime();
					}, 1000);
				}
				
				$('#getsmscode').on('click', function() {
					var mobile = $('input[name=mobile]').val();
					if (!mobile) {
						layer.msg('请输入电话号码');
					} else if (!telReg.test(mobile)) {
						layer.msg('请输入正确的电话号码');
					} else {
						$.get(server.queryusersmscode, {mobile:mobile}, function(res, status) {
							if (status == 'success') {
								if (res.code == 0) { 
									 settime();  
								} else {
									layer.msg(res.msg); 
								}
								closeloading();
							} else {
								closeloading();
								layer.msg('服务器连接错误');
							}
						});
					}
				})
				form.render(); 
				form.on('submit(LAY-user-login-smscode-submit)', function(obj) {
					console.log(obj.field);
					loading();
					submitdata_smscode(obj.field);
				});
				function submitdata_smscode(_data){
					$.post(server.login_smscode,_data,function(res,status){
						if(status == 'success'){
							if(res.code == 0){
								layer.msg('登录成功',{time: 200},function(){
									cookie.SetCookie('shop_token',res.system_token.data.token,365,domain,'/')
									cookie.SetCookie('shop_uid',res.system_token.data.userid,365,domain,'/')
									cookie.SetCookie('shop_roleid',res.member.data.role_id,365,domain,'/')
									location = '../index.html'
								});
							} else {
								layer.msg(res.msg);
							}
							closeloading();
						} else {
							layer.msg('服务器连接错误');
						}
					})
				}
			});
		</script>
	</body>

</html>